<template>
	<view>
		<Header :isBack="true">
			<block slot="content">{{title}}</block>
		</Header>

		<!-- 占位 -->
		<!-- <view class="place"></view> -->

		<empty v-if="isLoaded === false" :top="182"></empty>

		<view class="" v-show="isLoaded">
			<view class="list" v-if="jobData.length > 0">
				<view class="list-item" v-for="item in jobData" :key="item.id">
					<view class="img-wrapper">

						<view class="img-wrapper-header"
							@tap="checkDetail(item.id,item.interview_status,item.job_title)">
							<image class="pic" :src="item.logo">
							</image>
							<image v-if="item.interview_status == 0" class="status" src="@/static/images/weichakan.png">
							</image>
							<image v-if="item.interview_status == 1" class="status" src="@/static/images/yichakan.png">
							</image>
							<image v-if="item.interview_status == 2" class="status" src="@/static/images/yitongyi.png">
							</image>
							<image v-if="item.interview_status == 3" class="status" src="@/static/images/yijujue.png">
							</image>
							<view class="img-wrapper-center">
								<text>{{item.job_title}}{{item.interview_status}}</text>
								<image class="img-wrapper-center-button" src="@/static/images/rijie.png" alt=""></image>

							</view>
							<text class="img-wrapper-right">{{item.salary}}元/天</text>
						</view>


						<text class="introduce">
							{{item.description}}
						</text>
					</view>
					<view class="bot">
						<text class="bot-text">{{item.updatetime}}</text>
						<view class="bot-img-text">
							<image class="bot-img" src="@/static/images/place.png"></image>
							<text class="bot-text">{{item.location}}</text>
						</view>
					</view>
					<view class="operator" v-if="item.interview_status == 0 || item.interview_status == 1">
						<view class="operator-img-left">
							<image class="operator-img" src="/static/images/tongyiyaoqing.png"
								@click="handle(item.id,2)"></image>
						</view>
						<view class="operator-img-right">
							<image class="operator-img" src="/static/images/jujueyaoqing.png"
								@click="handle(item.id,3)"></image>
						</view>
					</view>
				</view>

			</view>
			<view class="empty" v-else>
				<image src="/static/images/zanwushuju.png" alt="" class="empty-img"></image>
			</view>
		</view>

		<!-- 底部菜单 -->
		<BottomTabbar :selected = "3"></BottomTabbar>
	</view>

</template>

<script>
	import BottomTabbar from '@/components/bottom-tabbar/bottom-tabbar.vue';
	import empty from "@/components/empty";
	export default {
		data() {
			return {
				title: '邀请记录',
				menuTop: '196',

				loadingText: "正在加载...",
				defaultSelected: [],

				jobData: [],
				page: 1,
				isLoaded: false,

			}
		},

		components: {
			BottomTabbar,
			empty
		},

		// 页面生命周期，下拉刷新后触发
		onPullDownRefresh() {
			//判断是否登录
			let result = this.$api.isLogin();
			if (result === false) {
				return false;
			}
			this.loadData()

			// 停止下拉刷新
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 600)
		},

		//下拉到底获取新的数据
		onReachBottom() {
			this.getNewJobs();
		},

		onLoad: function(option) {
			//判断是否登录
			let result = this.$api.isLogin();
			if (result === false) {
				return false;
			}

			uni.showLoading({
				title: '加载中...'
			});
			// this.title = option.title;
			this.loadData();
			setTimeout(() => {
				this.isLoaded = true;
				uni.hideLoading();
			}, 600)

		},
		methods: {
			async loadData() {
				this.page = 1;
				this.getNewJobs();
			},

			//职位列表
			async getNewJobs() {
				let token = uni.getStorageSync('token');
				let dataObj = {
					page: this.page,
					token: token
				}

				let jdata = await this.$myRequest({
					url: '/interviews',
					data: dataObj,
					methods: 'POST'
				})
				let ndata = jdata.data.data;

				if (this.page === 1) {
					this.jobData = ndata;
					if (ndata.length === 0) {
						this.$api.msg('亲！暂无数据！！！')
					} else {
						this.page = this.page + 1;
					}
				} else {
					if (ndata.length === 0) {
						if (this.jobData.length === 0) {
							this.$api.msg('亲！暂无数据！！！')
						} else {
							this.$api.msg('亲！已经到底了！！！')
						}

					} else {
						this.jobData = [...this.jobData, ...ndata];
						this.page = this.page + 1;
					}
				}
			},

			async checkDetail(id, interview_status, title) {
				let token = uni.getStorageSync('token')
				let dataObj = {
					token: token,
					job_id: id
				}
				if (interview_status == 0) {
					await this.$myRequest({
						url: '/isChecked',
						data: dataObj,
						methods: 'POST'
					})

				}

				//添加浏览记录
				await this.$myRequest({
					url: '/addBrowseJob',
					data: dataObj,
					methods: 'POST'
				})

				uni.navigateTo({
					url: '/pages1/pages/project-detail/project-detail?id=' + id + '&title=' + title + '详情'
				});
			},

			async handle(id, interview_status) {
				let token = uni.getStorageSync('token')
				let dataObj = {
					token: token,
					job_id: id,
					status: interview_status,
				}
				// console.log(dataObj)
				let resH = await this.$myRequest({
					url: '/interviewHandle',
					data: dataObj,
					methods: 'POST'
				})

				if (resH.data.status == 1) {
					this.$api.msg(resH.data.msg, 'success')
					setTimeout(() => {
						this.loadData()
					}, 1500)
				} else {
					this.$api.msg(resH.data.msg)
				}
			}
		}
	}
</script>
<style>
	page {
		background-color: #f7f7f7;
		font-size: $font-base;
	}
</style>
<style lang='scss' scoped>
	.list {
		// #ifdef APP-PLUS
		padding: 168rpx 17rpx 120rpx;
		// #endif
		
		// #ifdef H5
		padding: 108rpx 17rpx 120rpx;
		// #endif

		.list-item {
			background-color: #fff;
			display: flex;
			flex-direction: column;
			align-items: center;
			border-radius: 10rpx;
			margin-bottom: 15rpx;

			.img-wrapper {
				width: 100%;
				height: 286rpx;
				position: relative;
				padding: 27rpx;
				border-bottom: 1px solid #f3f3f6;

				.img-wrapper-header {
					margin-bottom: 27rpx;
					height: 112rpx;
					position: relative;

					.pic {
						width: 112rpx;
						height: 112rpx;
						border-radius: 6upx;
						margin-right: 17rpx;
					}

					.status {
						position: absolute;
						top: -26rpx;
						left: -26rpx;
						width: 101rpx;
						height: 53rpx;
					}

					.img-wrapper-center {
						height: 112rpx;
						display: inline-block;
						position: absolute;
						line-height: 56rpx;
						font-size: 30rpx;

						.img-wrapper-center-button {
							/* display: inline-block; */
							width: 63rpx;
							height: 39rpx;

							display: flex;
							align-items: center;
						}
					}

					.img-wrapper-right {
						position: absolute;
						top: 0;
						right: 0;
						color: #f3431a;
						font-size: 26rpx;
						line-height: 56rpx;
						height: 56rpx;
					}
				}

				.introduce {
					height: 96rpx;
					display: flex;
					flex-direction: column;
					line-height: 48rpx;
					font-size: $font-base !important;
					overflow: hidden;
					-webkit-line-clamp: 2;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					color: #676767;
				}
			}

			.bot {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 78rpx;
				font-size: 28upx;
				color: #676767;
				padding: 0 27rpx;
				width: 100%;
				border-bottom: 1px solid #f3f3f6;


				.bot-img-text {
					display: flex;
					align-items: center;
					justify-content: space-between;
					max-width: 360rpx;

					.bot-img {
						height: 28rpx;
						width: 26rpx;
						margin-right: 14rpx;

					}

					.bot-text {
						max-width: 320rpx;
						display: inline-block;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
				}
			}

			.operator {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 86rpx;
				/* font-size: 28upx; */
				color: #676767;
				padding: 0 27rpx;
				width: 100%;


				.operator-img-left,
				.operator-img-right {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 50%;
				}

				.operator-img-left {
					border-right: 1px solid #f3f3f6;
				}

				.operator-img {
					width: 170rpx;
					height: 55rpx;
				}
			}
		}
	}

	.place {
		padding-top: 108rpx;
		/* height: 122rpx; */
		width: 100%;
	}

	.order-title-box {
		background-color: #ffffff;

		.order-title {
			height: 78rpx;
			padding: 18rpx 42rpx 18rpx;
			display: flex;
			justify-content: space-between;

			.order-title-item {
				height: 42rpx;
			}
		}
	}

	.empty {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);

		.empty-img {
			width: 182rpx;
			height: 182rpx;
		}
	}
</style>
